Welcome

Best Practices and Strategies to Create Effective Visualizations

Aaron Williams

@awunderground

urban-logo

Best Practices and Strategies to Create Effective Visualizations

Why I Love R

Aaron Williams

@awunderground

urban-logo

WHY: Principles for selecting a data viz tool

1. Looks good!

ledecky

Source: fivethirtyeight

2. Flexible

3. Reproducible

4. Scalable

AKA “Please just don’t make me point-and-click 100 charts”

cat

5. In my analysis workflow

parallel

WHAT: R and ggplot2

Source: Hadley Wickham

Source: ggplot2

fivethirtyeight

Financial Times

BBC

HOW: Grammar of Graphics

Leland Wilkinson

Grammar of Graphics

Hadley Wickham

A Layered Grammar of Graphics

hadley

Source: Hadley Wickham

1. Data

name year category lat long wind pressure
Caroline 1975 -1 21.1 -85.1 25 1014
AL142003 2003 -1 11.4 -22.2 25 1009
Gabrielle 2001 0 27.1 -82.6 60 983
Andrew 1992 4 25.4 -77.5 125 930
Iris 1995 1 15.2 -53.8 70 992
Allison 2001 -1 31.5 -95.0 20 1005
Gilbert 1988 4 23.9 -97.0 115 950
Ike 2008 1 22.6 -82.9 70 965
Ida 2015 -1 19.7 -45.7 30 1005
Opal 1995 0 20.8 -91.6 50 985

ggplot(data = )

2. Aesthetic mappings

aes(x = , y = , color = )

X or Y

Color or Fill

Aesthetic mappings

Size

Shape

Others: transparency, animations, faceting

3. Geometric objects

Plots are often referred to by the name of their geometric object(s).

Bar

geom_bar()

3. Geometric objects

Line

geom_line()

3. Geometric objects

Point

geom_point()

3. Geometric objects

?

3. Geometric objects

Path of Hurricane Katrina

4. Scales

Before

scale_x_continuous()

After

scale_x_log10()

4. Scales

Before

scale_size_continuous(breaks = c(25, 75, 125))

After

scale_size_continuous(range = c(0.5, 20), breaks = c(25, 75, 125))

5. Coordinate systems

Cartesian

5. Coordinate systems

Polar

coord_polar()

6. Facets (optional)

Facet wrap

facet_wrap(~category)

6. Facets (optional)

Facet grid

facet_grid(month~status)

7. Statistical transformations (optional)

Count

8. Themes

Default theme

8. Themes

fivethirtyeight theme

8. Themes

urbnthemes

Coding example

stop

New? 9. Arrangements

arrangement

New? 9. Arrangements

Animation

New? Interactivity

Examples

urbnmapr

Pension code

In directory

R Shiny

Graphics guide

Strengths and Weaknesses

1. Looks good!

A

2. Flexible

B

Once you understand ggplot2, it is really useful for doing 90% of the results with 10% of the effort

(Jennfer Hill)

3. Reproducible

A+

4. Scalable

B+

5. In my analysis workflow

A+

Questions